<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>图片矫正工具</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            padding: 2rem;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: #f8f9fa;
            color: #212529;
        }

        .main-container {
            display: flex;
            gap: 2rem;
            max-width: 1200px;
            width: 100%;
            margin: 0 auto;
        }

        .container {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            background: white;
            padding: 1.5rem;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        h3 {
            font-size: 1.25rem;
            font-weight: 500;
            margin-bottom: 1rem;
            color: #1a73e8;
        }

        .upload-area {
            width: 100%;
            margin-bottom: 1rem;
            display: flex;
            gap: 0.5rem;
            align-items: center;
            justify-content: center;
        }

        #uploadButton {
            display: none;
        }

        .upload-label, .reset-points {
            padding: 0.5rem 1rem;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9rem;
            transition: background-color 0.2s;
        }

        .upload-label {
            background-color: #1a73e8;
            color: white;
        }

        .upload-label:hover {
            background-color: #1557b0;
        }

        .reset-points {
            background-color: #dc3545;
            color: white;
            border: none;
            opacity: 1;
        }

        .reset-points:hover {
            background-color: #bb2d3b;
        }

        button {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9rem;
            transition: all 0.2s;
        }

        #downloadButton {
            background-color: #198754;
            color: white;
        }

        #downloadButton:hover {
            background-color: #157347;
        }

        #canvasContainer {
            position: relative;
            margin: 1rem 0;
            border-radius: 8px;
            overflow: hidden;
            font-size: 0;
            line-height: 0;
        }

        canvas {
            display: block;
            max-width: 100%;
            height: auto;
            background-color: #fff;
            border-radius: 8px;
            image-rendering: -webkit-optimize-contrast;
            margin: 0;
            padding: 0;
        }

        #pointsContainer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
        }

        .point {
            position: absolute;
            width: 12px;
            height: 12px;
            background: #ff4444;
            border-radius: 50%;
            border: 2px solid white;
            box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
            margin-left: -6px;
            margin-top: -6px;
            pointer-events: none;
            z-index: 1000;
        }

        .point-label {
            position: absolute;
            left: 16px;
            top: -8px;
            color: #ff4444;
            font-size: 12px;
            font-weight: bold;
            text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
            z-index: 1001;
            line-height: normal;
        }

        #instructions {
            margin-top: 1rem;
            padding: 0.75rem;
            background-color: #e9ecef;
            border-radius: 6px;
            font-size: 0.9rem;
            color: #495057;
            text-align: center;
            width: 100%;
        }

        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
            }

            .container {
                width: 100%;
            }
        }

        #originalCanvas {
            cursor: crosshair;
        }
    </style>
    <script src="plugins/numeric/numeric.min.js"></script>
</head>
<body>
    <div class="main-container">
        <div class="container">
            <h3>原始图像</h3>
            <div class="upload-area">
                <input type="file" id="uploadButton" accept="image/*">
                <label for="uploadButton" class="upload-label">选择图片</label>
                <button id="resetPoints" class="reset-points">重置位置</button>
            </div>
            <div id="canvasContainer">
                <canvas id="originalCanvas" width="500" height="400"></canvas>
                <div id="pointsContainer"></div>
            </div>
            <div id="instructions">请上传图片并点击图像上的四个角点</div>
        </div>

        <div class="container">
            <h3>矫正后的图像</h3>
            <canvas id="correctedCanvas" width="500" height="400"></canvas>
            <button id="downloadButton" style="display: none; margin-top: 1rem;">下载矫正后的图片</button>
        </div>
    </div>

    <div style="display: none;">
        <canvas id="highResCanvas"></canvas>
    </div>

    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script> -->
    <script type="module">
        import { DOMHandler } from './domHandler.js';
        const domHandler = new DOMHandler();
    </script>
</body>
</html>
